﻿using System.Windows;
using System.Windows.Controls;

namespace content.A03
{
    public partial class A0308:Page
    {
        public A0308()
        {
            InitializeComponent();
        }

        private void RadioButton_Checked(object sender,RoutedEventArgs e)
        {
            if(result!=null)
            {
                result.Content="";
            }

            if(label==null) return;
            switch((e.Source as RadioButton)?.Content.ToString())
            {
                case"加法":
                    label.Content="+";
                    break;
                case"减法":
                    label.Content="-";
                    break;
                case"乘法":
                    label.Content="*";
                    break;
                case"除法":
                    label.Content="/";
                    break;
                case"取模":
                    label.Content="%";
                    break;
            }
        }

        private void Caculate_Click(object sender,RoutedEventArgs e)
        {
            if(!double.TryParse(textBox1.Text,out var n1)||!double.TryParse(textBox2.Text,out var n2))
            {
                result.Content="?";
                return;
            }

            const string format="{0:0.####}";
            switch(label.Content.ToString())
            {
                case"+":
                    result.Content=string.Format(format,n1+n2);
                    break;
                case"-":
                    result.Content=string.Format(format,n1-n2);
                    break;
                case"*":
                    result.Content=string.Format(format,n1*n2);
                    break;
                case"/":
                    if(n2==0) result.Content="?";
                    else result.Content=string.Format(format,n1/n2);
                    break;
                case"%":
                    if(n2==0) result.Content="?";
                    else result.Content=string.Format(format,n1%n2);
                    break;
            }
        }
    }
}